package com.share.device.emqx.config;

import com.share.device.emqx.config.domain.AuthDto;
import com.share.device.emqx.config.domain.AuthVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import static java.nio.file.attribute.AclEntryType.ALLOW;
import static java.nio.file.attribute.AclEntryType.DENY;

@Component
public class EmqxServiceImpl {
    @Autowired
    private EmqxProperties emqxProperties;

    public AuthVo auth(AuthDto authDto){
        //排除系统客户端
        if(authDto.getClientId().startsWith(emqxProperties.getClientId())){
            return new AuthVo.Builder()
                    .result(String.valueOf(ALLOW))
                    .build();
        }
        return new AuthVo.Builder()
                .result(String.valueOf(DENY))
                .build();
    }
}
